import { combineReducers, createStore } from 'redux'
import userReducer from './userReducer'

const rootReducer = combineReducers({
  user: userReducer,
  keyword: (state: string = '', action: {type: 'keyword', value: string}) => {
    if (action.value !== undefined) state = action.value
    return state
  }
})

const store = createStore(rootReducer)

export default store

// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch